Skip to content

Add experimental support for Event Groups (implicit and scope propagation) - #3198

Merged
mjameswh merged 4 commits into
mainfrom
event-groups-scopes
Nov 20, 2026
Merged

mjameswh merged 4 commits into
mainfrom
event-groups-scopes

Conversation

@mjameswh

@mjameswh mjameswh commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

Add experimental support for implicit Event Groups and scope-based propagation. This follows #3197, which added direct assignment.

  • EventGroup.run attaches the group to commands issued inside the callback. Nested scopes compose, and the earliest label for an id wins.
  • Signal and update handlers run in an implicit group for the signal event or the update. That scope replaces any scope that was active when the handler was registered. Update validators are not wrapped.
  • Direct addEventGroups and the active scope are additive.
  • A workflow thread started with Async.function or Async.procedure keeps the scope that was active when it was started.

Promise continuations (thenApply, handle, thenCompose, exceptionally) do not capture the scope. They run on the thread that completes the promise, which is how CancellationScope and WorkflowThreadLocal already behave. Adopting a different behavior only for Event Groups would be inconsistent with other existing APIs. Extending context propagation on all APIs to also propagate to Promise continuations seems a desirable thing on the long term, but it is outside the scope of this PR, and would be a breaking behavior changes for existing workflows; we instead propose to delay this until the Java v2 SDK.

@mjameswh mjameswh changed the title Event groups scopes Add experimental support for Event Groups (implicit and scope propagation) Nov 10, 2026
Base automatically changed from event-groups-direct-only to main November 18, 2026 13:33
Commands issued inside EventGroup.run, and from signal and update handlers, carry the active groups. Promise continuations do not capture that scope.
@mjameswh
mjameswh force-pushed the event-groups-scopes branch from c018f14 to 4fb7280 Compare November 18, 2026 14:23
@mjameswh
mjameswh marked this pull request as ready for review November 18, 2026 14:56
@mjameswh
mjameswh requested a review from a team as a code owner November 18, 2026 14:56
threadContext.initialYield();
cancellationScope.run();
eventGroupScope.run(
() -> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an overload for this case to just write eventGroupScope.run(cancellationScope::run)

TimerOptions.newBuilder()
.addEventGroups(options.getEventGroups().toArray(new EventGroup[0]))
.build())
eventGroupScope

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does change the overload that gets called in the interceptors, was this intentional? I think we changed this call when you first added event groups so maybe a NOOP

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's intentional. This restores interceptor that was original called before #3197, given that we can now pass EGs through scope propagation instead of direct attachment. Not breaking since we haven't published a release between PR 3197 and now.

I anticipate we may want to come back to the two args form at some point to propagate other options that will not support scope-propagation, like user metadata, but there's no reason to do this today.

}

@Override
public <R> R run(Functions.Func<R> func) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we could add a check that we are in a workflow here

@mjameswh
mjameswh merged commit d43fce7 into main Nov 20, 2026
23 of 24 checks passed
@mjameswh
mjameswh deleted the event-groups-scopes branch November 20, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants